package com.tourex.ui.view.app;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.tourex.App;
import com.tourex.BaseActivity;
import com.tourex.C.bean.TourProjectInfo;
import com.tourex.R;
import com.tourex.ui.WapActivity;
import com.tourex.utils.BaseUtils;

public class TourProjectInfoLayout extends FrameLayout {

	private View layContent;
	private ImageView imgTourProjectInfo;
	private TextView txTitle, txDistance;
	private View layDistance;

	public TourProjectInfoLayout(Context context) {
		this(context, null);
	}

	public TourProjectInfoLayout(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public TourProjectInfoLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);

		LayoutInflater.from(getContext()).inflate(R.layout.layout_tour_info_detail, this);

		layContent = findViewById(R.id.lay_content);
		imgTourProjectInfo = (ImageView) findViewById(R.id.img_tour_info);
		txTitle = (TextView) findViewById(R.id.tx_title);
		txDistance = (TextView) findViewById(R.id.tx_distance);
		layDistance = findViewById(R.id.layout_distance);
	}

	public void setData(final TourProjectInfo tpi, final String type, int reqHeight) {
		reqHeight = BaseUtils.dip(getContext(), reqHeight);
		layContent.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, reqHeight));

		App.i().imageLoader.get(tpi.img, BaseActivity.getDefaultImageListener(imgTourProjectInfo));

		txTitle.setText(tpi.title);
		// txDistance.setText(String.format(getResources().getString(R.string.distance_1),
		// String.format("%.1f", tpi.jl / 1000)));
		txDistance.setText(String.format(getResources().getString(R.string.distance_1), String.valueOf(tpi.jl)));

		layDistance.setVisibility(tpi.jl == 0d ? View.GONE : View.VISIBLE);

		this.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// if (C.convention.type_cz.equals(type)) {
				// GeneralListActivity.actionStart(getContext(), type, tpi.id);
				// } else {
				// if (TextUtils.isEmpty(tpi.url)) {
				// ((BaseActivity) getContext()).showToast(R.string.null_url);
				// } else {
				// WapActivity.actionStart(getContext(), tpi.url, type,
				// tpi.phone, tpi.jd, tpi.wd);
				// }
				// }

				if (TextUtils.isEmpty(tpi.url)) {
					((BaseActivity) getContext()).showToast(R.string.null_url);
				} else {
					WapActivity.actionStart(getContext(), tpi.url, type, tpi.phone, tpi.jd, tpi.wd);
				}
			}
		});
	}
}
